package com.jinxin.platform.cdfaceacs.utils;

import com.alibaba.fastjson.JSON;
import com.jinxin.platform.cdfaceacs.pojo.dto.RuleDto;
import com.jinxin.platform.cdfaceacs.redis.RedisUtil;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;

/**
 * Date: 2021-05-10
 * Author: yangjie
 * desc:
 **/
@Component
public class RuleComponent {
    @Resource
    RedisUtil redisUtil;

    public RuleDto getConfig() {
        String content = (String) redisUtil.get(MyConstants.REDIS_ATTENDANCE_CONFIG_OBJ);
        if (!StringUtils.isEmpty(content)) {
            return JSON.parseObject(content, RuleDto.class);
        } else {
            RuleDto ruleDto = new RuleDto();
            ruleDto.setSignInDate("08:00:00");
            ruleDto.setSignOutDate("18:00:00");
            ruleDto.setLateMinutes(10);
            ruleDto.setLeaveEarlyMinutes(10);
            ruleDto.setAbsenteeismMinutes(30);
            return ruleDto;
        }

    }

    public void setConfig(RuleDto configForm) {
        redisUtil.set(MyConstants.REDIS_ATTENDANCE_CONFIG_OBJ, JSON.toJSONString(configForm));
    }
}
